package net.caixiaomi.info.widgets;

import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;

/**
 * 监听输入的内容，将mTarget 的View状态改变
 */

public class InputEditTextWatcher implements TextWatcher {
    private View mTarget;

    public InputEditTextWatcher(View target) {
        mTarget = target;
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        String text = s.toString();
        mTarget.setSelected(!TextUtils.isEmpty(text));
    }

    @Override
    public void afterTextChanged(Editable s) {
        String text = s.toString();
        if (!TextUtils.isEmpty(text)) {
            char c = s.charAt(s.length() - 1);
            if (Character.isSpaceChar(c)) {
                s.delete(s.length() - 1, s.length());
            }
        }
    }
}
